//package org.activoricordi.app.snippet
package edu.ucdavis.fiehnlab.alchemy.alchemyAdmin.snippet

/**
 * Created with IntelliJ IDEA.
 * User: naru
 * Date: 3/30/13
 * Time: 11:39 AM
 * To change this template use File | Settings | File Templates.
 */


import net.liftweb._
import http.S
import http.SHtml._
import net.liftweb.mapper._

import net.liftweb.common.{Box,Full,Empty,Failure,ParamFailure}
import util._

import  edu.ucdavis.fiehnlab.alchemy.alchemyAdmin.model._
import scala.xml._
import util.Helpers._

class AddCompound {


  def create(form : NodeSeq): NodeSeq = {
    val compound = new Compound()
    var selectedMethod = "None"
    val method = new Method()



    val methodList = Method.findAll.map(a => (a.id.toString , a.name.is))
    /**
     * create a forum to input Method
     */
    // method.toForm(Full("save"), {_.save})
    def processEntryAdd () {
      /**
       * validate input data
       */
      compound.validate match {
        case Nil =>  compound.save

        case errors:List[FieldError] => S.error(errors)
      }
      S.redirectTo("/compound/list")}

    // method mapFieldTitleForm  ({  i =>
    def doBind(form: NodeSeq) =
      bind("compound", form,
     // "method" -> select(methodList ,Empty,chosenMethod => { selectedMethod =chosenMethod
    //  } ),
     "method" -> compound.method.toForm,
        "compoundName" -> compound.compoundName.toForm,
        "inchiKey" ->  compound.inchiKey.toForm,
        "origin" -> compound.origin.toForm,
        "retentionTime" -> compound.retentionTime.toForm,
        "theoreticalMass" -> compound.theoreticalMass.toForm,
        "massWindowFactor" -> compound.massWindowFactor.toForm,
        "expectedIntensity" -> compound.expectedIntensity.toForm,
        "internalStandard" -> compound.internalStandard.toForm,
        "massSpectra" -> compound.massSpectra.toForm,
        "comments" -> compound.comments.toForm,
        "submit" -> submit("Add", processEntryAdd))
    // })     openOr Text("Invalid Item")
    doBind(form)
  }
     /**
  def create(html : NodeSeq): NodeSeq = {
    val compound = new Compound()

    /**
     * create a forum to input Compound
     */
    compound.toForm(Full("save"), {_.save})
  }
    **/
}
